#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <string>
#include <cstring>
#include <cstdio>

pthread_mutex_t glock = PTHREAD_MUTEX_INITIALIZER;

pthread_cond_t gcond = PTHREAD_COND_INITIALIZER;

void *rountine(void *args)
{
    char *str = static_cast<char *>(args);
    while (1)
    {
        pthread_mutex_lock(&glock);
        printf("%s", str);
        pthread_cond_wait(&gcond, &glock);
  

        pthread_mutex_unlock(&glock);
    }
}
int main()
{
    pthread_t threadA, threadB;

    pthread_create(&threadA, NULL, rountine, (void *)"我是线程A\n");
    pthread_create(&threadB, NULL, rountine, (void *)"我是线程B\n");

    for (int i = 0;i < 5;i++)
    {
        pthread_cond_signal(&gcond);
        sleep(1);
    }
    pthread_cancel(threadA);
    pthread_cancel(threadB);

    pthread_join(threadA, NULL);
    pthread_join(threadB, NULL);

    return 0;
}